
#message(STATUS "-----------EXOSIP_ROOT:${EXOSIP_ROOT}")
if(NOT EXOSIP_ROOT)
  message(STATUS "The system default installation directory will be used to search exosip"
                 ", You can manually specify resip package directory by using -DEXOSIP_ROOT=<path>")
elseif(NOT EXISTS "${EXOSIP_ROOT}")
  message(FATAL_ERROR "Invalid exosip source package path:${EXOSIP_ROOT}")
endif()

find_path(_EXOSIP_INC_DIR NAMES "eXosip2/eXosip.h" HINTS "${EXOSIP_ROOT}/include")
find_path(_OSIP_INC_DIR NAMES "osip2/osip.h" HINTS "${EXOSIP_ROOT}/../osip/include")

list(APPEND _libs_search_dirs "${EXOSIP_ROOT}/platform/vsnet/${CMAKE_VS_PLATFORM_TOOLSET}/Win32"
                              "${EXOSIP_ROOT}/platform/vsnet/${CMAKE_VS_PLATFORM_TOOLSET}/x64"
                              "${EXOSIP_ROOT}/../osip/platform/vsnet/${CMAKE_VS_PLATFORM_TOOLSET}/Win32"
                              "${EXOSIP_ROOT}/../osip/platform/vsnet/${CMAKE_VS_PLATFORM_TOOLSET}/x64"
                              "${EXOSIP_ROOT}/src"
                              "${EXOSIP_ROOT}/../osip/src/osip2"
                              "${EXOSIP_ROOT}/../osip/src/osipparser2"
                              "${EXOSIP_ROOT}/../c-ares"
                              "${EXOSIP_ROOT}/../c-ares/src/lib")
list(APPEND _libs_search_suffixs "Debug" "Release" ".libs")
find_library(_EXOSIP_LIB
             NAMES "eXosip2" "eXosip"
             HINTS ${_libs_search_dirs}
             PATH_SUFFIXES ${_libs_search_suffixs})
find_library(_OSIP_LIB
             NAMES "osip2"
             HINTS ${_libs_search_dirs}
             PATH_SUFFIXES ${_libs_search_suffixs})
find_library(_OSIPPARSE_LIB
             NAMES "osipparser2"
             HINTS ${_libs_search_dirs}
             PATH_SUFFIXES ${_libs_search_suffixs})
find_library(_CARES_LIB
             NAMES "libcaresd" "libcares" "caresd" "cares"
             HINTS ${_libs_search_dirs}
             PATH_SUFFIXES ${_libs_search_suffixs})

list(APPEND Exosip_INCLUDE_DIRS ${_EXOSIP_INC_DIR} ${_OSIP_INC_DIR})
list(APPEND Exosip_LIBRARIES ${_EXOSIP_LIB} ${_OSIP_LIB} ${_OSIPPARSE_LIB} ${_CARES_LIB})

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Exosip
  FOUND_VAR Exosip_FOUND
  REQUIRED_VARS Exosip_INCLUDE_DIRS _EXOSIP_LIB _OSIP_LIB _OSIPPARSE_LIB _CARES_LIB
)


